#include <iostream>

using namespace std;

int calc(int num1, int num2, char op);

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int num1, num2, num3;
        char op1, op2;
        cin >> num1 >> op1 >> num2 >> op2 >> num3;

        int res = 0;
        if (op2 == '*') {
            res = num2 * num3;
            res = calc(num1, res, op1);
        } else {
            res = calc(num1, num2, op1);
            res = calc(res, num3, op2);
        }
        cout << res << endl;
    }
}

int calc(int num1, int num2, char op) {
    switch (op) {
        case '+':
            return num1 + num2;
        case '-':
            return num1 - num2;
        case '*':
            return num1 * num2;
        default:
            return 0;
    }
    return 0;
}